package com.gewu.pm.ui.activity.terminal;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.bean.ManagementBean;
import com.gewu.pm.ui.activity.base.BaseManagementActivity;
import com.gewu.pm.ui.activity.filter.FilterTerminalManagementActivity;
import com.gewu.pm.ui.activity.sales.SalesLeadAddActivity;
import com.gewu.pm.ui.adapter.customer.TerminalAdapter;

/**
 * 终端管理
 */
public final class TerminalManagementActivity extends BaseManagementActivity<ManagementBean> {

    public static void start(Context context) {
        Intent intent = new Intent(context, TerminalManagementActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected String getPageTitle() {
        return "终端管理";
    }

    @Override
    protected String getSearchHint() {
        return "输入终端名称/终端编码";
    }

    @Override
    protected String getBottomButtonText() {
        return "新增终端";  // 显示底部按钮
    }

    @Override
    protected AppAdapter<ManagementBean> createAdapter() {
        return new TerminalAdapter(getContext());
    }

    @Override
    protected void loadData() {
        mDataList.clear();
        mDataList.add(new ManagementBean("终端名称展示在这里","1"));//暂时用1表示有营业执照
        mDataList.add(new ManagementBean("落落超市","2"));//暂时用2表示无营业执照

        // 保存原始数据用于搜索
        setOriginalData(mDataList);

        mAdapter.setData(mDataList);
        updateEmptyView();
    }

    @Override
    protected String getSearchText(ManagementBean item) {
        // 搜索终端名称（item 左上角的文字）
        return item.getName();
    }

    @Override
    protected void onBottomButtonClick() {
        SalesLeadAddActivity.start(getActivity(), 1);
    }

    @Override
    public void onItemClick(RecyclerView recyclerView, View itemView, int position) {
        ManagementBean item = mAdapter.getItem(position);
        // 跳转到终端详情，传递名称和ID（ID用于判断是否有营业执照）
        TerminalDetailActivity.start(getContext(), item.getName(), item.getId());
    }

    @Override
    public void onRightClick(View view) {
        super.onRightClick(view);
        FilterTerminalManagementActivity.start(getActivity());
    }
}
